package com.ruoyi.resturant.service.impl;

import com.ruoyi.common.exception.BizException;
import com.ruoyi.resturant.domain.ResBanner;
import com.ruoyi.resturant.mapper.ResBannerMapper;
import com.ruoyi.resturant.service.IResBannerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ResBannerServiceImpl implements IResBannerService {

    private static final Logger log = LoggerFactory.getLogger(ResBannerServiceImpl.class);

    @Autowired
    private ResBannerMapper resBannerMapper;

    /**
     * 查询轮播图
     *
     * @param id 轮播图主键
     * @return 轮播图
     */
    @Override
    public ResBanner selectBannerById(Long id) {return resBannerMapper.selectBannerById(id);
    }// 23201012809纪人豪

    @Override
    public List<ResBanner> selectBannerByParam(String bannerName) {
        return resBannerMapper.selectBannerByParam(bannerName);
    }// 23201012809纪人豪

    /**
     * 新增轮播图
     *
     * @param resBanner 轮播图
     * @return 结果
     */
    @Override
    public int insertBanner(ResBanner resBanner) {
        resBanner.setCreateTime(new Date());
        return resBannerMapper.insertBanner(resBanner);
    }// 23201012809纪人豪

    /**
     * 修改轮播图
     *
     * @param resBanner 轮播图
     * @return 结果
     */
    @Override
    public int updateBanner(ResBanner resBanner) {
        resBanner.setUpdateTime(new Date());
        return resBannerMapper.updateBanner(resBanner);
    }// 23201012809纪人豪

    /**
     * 删除轮播图信息
     *
     * @param id 轮播图主键
     * @return 结果
     */
    @Override
    public int deleteBannerById(Long id) {

        //根据轮播图ID查询数据库中是否存在
        ResBanner resBanner = resBannerMapper.selectBannerById(id);
        //不存在的话, 抛出异常
        if (resBanner == null) {
            throw new BizException(404, "该轮播图id" + id + "不存在");
        }
        log.info("该轮播图id" + id + "存在");
        //存在的场合, 删除该轮播图
        return resBannerMapper.deleteBannerById(id);
    }// 23201012809纪人豪
}



